package com.common.user.domain;

import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import org.springframework.data.jpa.domain.AbstractPersistable;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@Entity
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler", "new"})
public class Organization extends AbstractPersistable<Long> {

	private static final long serialVersionUID = 1L;
	
	@Column(unique = true)
	private String code;
	
	private String name;
	
	private String cls;
	//1:company 2：department
	private Integer type;
	
	private Boolean isParent;
	
	@ManyToOne
	@JoinColumn(name = "parent_id")
	@JsonIgnoreProperties("children")
	private Organization parent;
	
	@OneToMany(mappedBy = "parent", cascade = CascadeType.REMOVE)
	@JsonIgnoreProperties("parent")
	private Set<Organization> children = new LinkedHashSet<>();

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCls() {
		return cls;
	}

	public void setCls(String cls) {
		this.cls = cls;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public Boolean getIsParent() {
		return isParent;
	}

	public void setIsParent(Boolean isParent) {
		this.isParent = isParent;
	}

	public Organization getParent() {
		return parent;
	}

	public void setParent(Organization parent) {
		this.parent = parent;
	}

	public Set<Organization> getChildren() {
		return children;
	}

	public void setChildren(Set<Organization> children) {
		this.children = children;
	}
	
}
